package org.mathig.poker.util;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Random;

public class RandomUtils {

	public static Random random = new Random();

	public static void shuffle(Object[] array) {
		List<Object> remaining = new ArrayList<Object>(Arrays.asList(array));
		for (int i = 0; i < array.length; i++) {
			Object obj = remaining.remove(random.nextInt(remaining.size()));
			array[i] = obj;
		}
	}

	@SuppressWarnings("unchecked")
	public static <T> void shuffle(List<T> list) {
		List<Object> remaining = new ArrayList<Object>(list);
		list.clear();
		while (remaining.size() > 0) {
			T obj = (T) remaining.remove(random.nextInt(remaining.size()));
			list.add(obj);
		}
	}
}
